package com.treetao.union.web.controller.system;


import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.treetao.union.db.model.SysSite;
import com.treetao.union.db.model.vo.RestResponse;
import com.treetao.union.web.constant.Constants;
import com.treetao.union.web.controller.BaseAdminController;

/**
 * <p>
 *  前端控制器
 * </p>
 */
@Controller
@RequestMapping(Constants.AMIND_PREFIX + "/system/site")
public class SysSiteController extends BaseAdminController{


    @RequiresPermissions("sys:site:list")
    @GetMapping("show")
    public String show(Model model){
        SysSite site = sysSiteService.getCurrentSite();
        model.addAttribute("site",site);
        return "admin/system/site/show";
    }

    @RequiresPermissions("sys:site:edit")
    @PostMapping("edit")
    @ResponseBody
    public RestResponse edit(SysSite site){
        if(site.getId() == null){
            return RestResponse.failure("ID不能为空");
        }
        if(site.getId() != 1){
            return RestResponse.failure("ID不正确");
        }
        if(StringUtils.isBlank(site.getName())){
            return RestResponse.failure("站点名称不能为空");
        }
        sysSiteService.updateSite(site);
        return RestResponse.success();
    }
}
